#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e4 + 5;
const int M = 1e5 + 5;

int n, m;
int head[N];
int ver[M << 1], Next[M << 1], tot = 1;
ll W[M << 1];
void add(int u, int v, ll w) {
  ++tot;
  ver[tot] = v;
  W[tot] = w;
  Next[tot] = head[u];
  head[u] = tot;
}
bool vis[N];
ll d[N];
ll p[65];
void add(ll x) {
  ll now = x;
  for (ll i = 59; i >= 0; i--) {
    if (now & (1ll << i)) {
      if (p[i])
        now ^= p[i];
      else {
        p[i] = now;
        return;
      }
    }
  }
}
void dfs(int u, int e, ll now, vector<int>& path) {
  if (vis[u]) {
    add(now ^ d[u]);
    return;
  }
  vis[u] = 1, d[u] = now;
  for (int i = head[u]; i; i = Next[i]) {
    if ((e ^ i) == 1) continue;
    ll w = W[i];
    int v = ver[i];
    path.push_back(v);
    dfs(v, i, now ^ w, path);
    path.pop_back();
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, m) {
    int u, v;
    ll w;
    cin >> u >> v >> w;
    add(u, v, w), add(v, u, w);
  }
  vector<int> path;
  path.push_back(1);
  dfs(1, 0, 0, path);
  ll ans = d[n];
  per(i, 59, 0) { ans = max(ans, ans ^ p[i]); }
  cout << ans;
  return 0;
}